package com.example.smartcs.controller;

import com.example.smartcs.model.ChatRequest;
import com.example.smartcs.model.ChatResponse;
import com.example.smartcs.service.CustomerServiceAgent;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/api/chat")
@RequiredArgsConstructor
public class ChatController {

    private final CustomerServiceAgent customerServiceAgent;

    @PostMapping
    public ResponseEntity<ChatResponse> chat(@RequestBody ChatRequest request) {
        log.info("收到聊天请求: {}", request);
        try {
            ChatResponse response = customerServiceAgent.processRequest(request);
            log.info("生成回复: {}", response);
            return ResponseEntity.ok(response);
        } catch (Exception e) {
            log.error("处理聊天请求失败", e);
            return ResponseEntity.internalServerError().build();
        }
    }
    
    @GetMapping("/health")
    public ResponseEntity<String> healthCheck() {
        return ResponseEntity.ok("智能客服系统运行正常");
    }
} 